package com.eshop.product.controller;

import com.eshop.product.model.ProductSpecification;
import com.eshop.product.service.ProductSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName CategoryController
 * @Description
 * @Author 47980
 * @Date 2020/5/17 16:18
 * @Version V_1.0
 **/
@RestController
@RequestMapping("/product-specification")
public class ProductSpecificationController {

    @Autowired
    private ProductSpecificationService productSpecificationService;

    @GetMapping("/add")
    public String add (ProductSpecification productSpecification, String operationType) {
        try {
            productSpecificationService.add(productSpecification, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";

    }

    @GetMapping("/update")
    public String update (ProductSpecification productSpecification, String operationType) {
        try {
            productSpecificationService.update(productSpecification, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/delete")
    public String delete (Long id, String operationType) {
        try {
            productSpecificationService.delete(id, operationType);
        } catch (Exception e) {
            return e.getMessage();
        }
        return "success";
    }

    @GetMapping("/findById")
    public ProductSpecification findById (Long id) {
        return productSpecificationService.findById(id);
    }

    @GetMapping("/findByProductId")
    public ProductSpecification findByProductId (Long productId) {
        return productSpecificationService.findByProductId(productId);
    }
}
